package com.woniu113.junk.commons.exception;


import com.woniu113.junk.commons.model.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常处理类
 */
@RestControllerAdvice
public class JunkExceptionHandler {

    /**
     * 系统异常(不属于自定义异常的其他异常)
     */
    @ExceptionHandler(Exception.class)
    public Result<?> exceptionHandler(Exception e){

        e.printStackTrace();
        return Result.getResult().setCode(500).setMsg("出现异常");
    }

    /**
     * 自定义WoniuMovieException异常
     */
    @ExceptionHandler(WoniuJunkException.class)
    public Result<?> movieExceptionHandler(WoniuJunkException e){
        e.printStackTrace();
        return Result.getResult().setCode(e.getCode()).setMsg(e.getMessage());
    }
}
